function init_cmemoreceived() {
	if(cmemor_yui_table_instance == null){
		create_cmemoreceived_yui_table();
	}
	
	clear_cmemoreceived_yui_table();
 
	var dwrCallMetaData = {
			callback : success_fetchcmemorecd,
			exceptionHandler : exception_generic_handler,
			timeout : 100000,
			errorHandler : exception_generic_handler
		};
	
	if(usr_comp_cache == null) {setTimeout(init_cmemoreceived, 1000); return;}
	
	DWR_Invoice.fetchCreditMemoReceived(usrcompany_uid,dwrCallMetaData);
}

var cmemo_recd_cache = null;
function success_fetchcmemorecd(dwrresp){
	clear_cmemoreceived_yui_table();
	
	if(dwrresp.objRespOrError != null && dwrresp.objRespOrError.length > 0){
		cmemo_recd_cache = dwrresp.objRespOrError;
		cmemor_yui_table_instance.addRows(dwrresp.objRespOrError);
	}
}

var cmemor_yui_table_instance = null;
function create_cmemoreceived_yui_table() {
	if(cmemor_yui_table_instance == null){
	var invrcolumnDefs = [ 
{
	key : "selectThis",
	label : "Select",
	formatter : "radio",
	sortable : false,hidden:true
},                
	                       {
		key : "creditMemoNumber",
		label : "Credit Memo#",
		formatter: "hlinkFormatter",
		sortable : true
	} /*, {
		key : "supplierNameText",
		label : "Supplier",
		sortable : true
	}*/, {
		key : "creditMemoSubmittedDate",
		label : "Credit Memo Date",
		formatter: "date",
		sortable : true
	} , {
		key : "totalCreditMemoAmount",
		label : "Amount",
		formatter: "currency"
	} ];

	var invrDataSource = new YAHOO.util.DataSource();
	invrDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
	 var oConfigs = {
             paginator: new YAHOO.widget.Paginator({
                 rowsPerPage: 2
                 
             }),
             initialRequest: "results=504",
             width: "600px",
             // we'll leave the actual loading for later
 			initialLoad:true, 
 				
 			// This function links the master to the nested tables
 			generateNestedRequest: function (record) {
 				return lineItemData;

 			}
     };

	 cmemor_yui_table_instance = new YAHOO.widget.DataTable("cmemoreceived_yui_table",invrcolumnDefs,invrDataSource,oConfigs);
	 cmemor_yui_table_instance.set("selectionMode", "single");
	 cmemor_yui_table_instance.subscribe("rowClickEvent",
			 cmemor_yui_table_instance.onEventSelectRow);
	}

}

function clear_cmemoreceived_yui_table() {
	if (cmemor_yui_table_instance != null && cmemor_yui_table_instance.getRecordSet() != null && cmemor_yui_table_instance.getRecordSet().getLength() > 0) {
		var length = cmemor_yui_table_instance.getRecordSet().getLength();
		if (length > 0) {
			cmemor_yui_table_instance.deleteRows(0, length);
		}
	}
}